import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  }
]

export const asyncRoutes = [
  {
    path: '/deviceMsg',
    component: Layout,
    meta: { title: '设备管理', icon: 'tab' },
    children: [
      {
        path: '/device',
        component: () => import('@/views/device/index'),
        name: 'device',
        meta: { title: '设备信息管理', icon: 'icon', noCache: true }
      }, {
        path: '/deviceType',
        component: () => import('@/views/deviceType/index'),
        name: 'deviceType',
        meta: { title: '设备类型管理', icon: 'tab' }
      }, {
        path: '/dataItem',
        component: () => import('@/views/dataItem/index'),
        name: 'dataItem',
        meta: { title: '数据项管理', icon: 'tab' }
      }, {
        path: '/maintainMsg',
        component: () => import('@/views/maintain/index'),
        name: 'maintain',
        meta: { title: '维保管理', icon: 'tab' }
      }, {
        path: '/fileListMsg',
        component: () => import('@/views/fileList/index'),
        name: 'fileList',
        meta: { title: '文件管理', icon: 'tab' }
      }, {
        path: '/versionManage',
        component: () => import('@/views/versionManage/index'),
        name: 'versionManage',
        meta: { title: '版本管理', icon: 'tab' }
      }, {
        path: '/workOrderMsg',
        component: () => import('@/views/workOrder/index'),
        name: 'workOrder',
        meta: { title: '工单管理', icon: 'tab' }
      }
    ]
  },
  // 设备类型
  //功能管理
  // {
  //   path: '/deviceTypeFuncMsg',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'deviceTypeFunc',
  //       component: () => import('@/views/deviceTypeFunc/index'),
  //       name: 'deviceTypeFunc',
  //       meta: { title: '功能管理', icon: 'tab' }
  //     }
  //   ]
  // },
  //用户
  {
    path: '/webUserMsg',
    component: Layout,
    meta: { title: '用户管理', icon: 'tab' },
    children: [
      {
        path: '/webUser',
        component: () => import('@/views/webUser/index'),
        name: 'webUser',
        meta: { title: '系统用户', icon: 'tab' }
      },
      {
        path: '/agentUser',
        component: () => import('@/views/webUser/index_agent'),
        name: 'agentUser',
        meta: { title: 'App用户', icon: 'tab' }
      },
      {
        path: '/wechartUser',
        component: () => import('@/views/webUser/index_wechart'),
        name: 'wechartUser',
        meta: { title: '微信用户', icon: 'tab' }
      },
      //     {
      //       path: 'webAuditUserMsg',
      //       component: () => import('@/views/webAuditUser/index'),
      //       name: 'webAuditUser',
      //       meta: { title: '用户审核', icon: 'tab' }
      //     },
      {
        path: '/functionPermission',
        component: () => import('@/views/functionPermission/index'),
        name: 'functionPermission',
        meta: { title: '权限配置', icon: 'tab' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
